module.exports=(req)=>{
  let type = req.headers['content-type'];
  let dwg = {parameter:{},temporary:{}};
  //解析post数据
  return new Promise((resolve,err)=>{
      req.on('data', chunk => {
            //开启解析请求类型
          if(type.startsWith("multipart/form-data;")){
            let head = "2d2d"+Buffer.from(type.split("=")[1]).toString('hex');
            require('./form-data')(dwg,chunk.toString("hex"),head,head+"2d2d");
          }else if(type.startsWith("application/x-www-form-urlencoded;")){
            require('./form-urlencoded')(dwg,chunk.toString("hex"));
          }else if(type.startsWith('application/json;')){
            require('./json')(dwg,chunk.toString("hex"));
          }else{
            //默认为json格式
            require('./json')(dwg,chunk.toString("hex"));
          }
      });
      req.on('end', () => {
        //路由参数和post参数合并
        dwg.parameter = Object.assign(dwg.parameter,req.$route_parameter?req.$route_parameter:{})
        //与请求头合并
        for(let a in dwg.parameter){req[a]=dwg.parameter[a]}
        req.$all=(key)=>{
          if(key){return dwg.parameter[key]}
          return dwg.parameter; 
        }
        //返回数据
        resolve(dwg.parameter);

      })
      req.on('err', (e)=>{err(e)})
  });
}
